﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Text;
using System.Data;
using fanfu.Business;
using fanfu.Model;
using fanfu.Common;

public partial class PhotoAlone : BasePage
{
    public StringBuilder PhotoListHtml = new StringBuilder();
    public StringBuilder ReviewListHtml = new StringBuilder();

    protected void Page_Load(object sender, EventArgs e)
    {
        string group = string.Empty;
        string id = string.Empty;
        IPLocation ipLocation = new QQWryLocator().Query(Request.UserHostAddress);

        #region 验证参数正确性
        try
        {
            group = Request["group"].ToString();
        }
        catch (Exception ex) 
        {
            group = "0";
        }
        try
        {
            id = Request["id"].ToString();
        }
        catch (Exception ex) 
        {
            id = "0";
        }
        #endregion

        CreatePhotoListHtml(group);
        ReviewListHtml = new ReviewRule().CreateReviewListHtml(id, (int)ReviewParentType.image);

        RunJavascript("window.onload=function(){$('#photo" + id + "').click();};", true);
        this.ParentId.Value = id;
        this.ParentType.Value = ((int)ReviewParentType.image).ToString();
        this.ReviewerIP.Value = ipLocation.IP + ipLocation.Country + ipLocation.Local;
    }

    #region 根据相册ID创建相片列表
    /// <summary>
    /// 根据相册ID创建相片列表
    /// </summary>
    /// <param name="group"></param>
    private void CreatePhotoListHtml(string group)
    {
        DataTable photoList =new UploadFileRule().GetPhotoListByParentId(group);
        foreach (DataRow dr in photoList.Rows)
        { 
            PhotoListHtml.AppendFormat("<li><a id=\"photo{0}\" des=\"{1}\" name=\"{2}\" href=\"javascript:\"><img src=\"{3}\" /></a></li>"
                ,dr["ID"].ToString(), dr["FileDes"].ToString(), dr["SavePath"].ToString().Replace("~/", ""), dr["SmallImagePath"].ToString().Replace("~/", ""));
        }
        PhotoListHtml.Append("<li><a id=\"photo_back\" href=\"javascript:\"><img src=\"images/photo_back.jpg\" /></a></li>");
    }
    #endregion
}